package com.example.demo.Handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MyMetaObject implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("数据正在插入");
        this.setFieldValByName("userGmtCreate",new Date(),metaObject);
        this.setFieldValByName("userGmtUpdate",new Date(),metaObject);

        this.setFieldValByName("taskGmtCreate",new Date(),metaObject);
        this.setFieldValByName("taskGmtUpdate",new Date(),metaObject);

        this.setFieldValByName("hTaskGmtUpdate",new Date(),metaObject);
        this.setFieldValByName("hTaskGmtCreate",new Date(),metaObject);

        this.setFieldValByName("hSignInGmtCreate",new Date(),metaObject);
        this.setFieldValByName("hSignInGmtUpdate",new Date(),metaObject);
        log.info(String.valueOf(new Date()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("数据正在更新");
        this.setFieldValByName("userGmtUpdate",new Date(),metaObject);

        this.setFieldValByName("taskGmtUpdate",new Date(),metaObject);

        this.setFieldValByName("hTaskGmtUpdate",new Date(),metaObject);

        this.setFieldValByName("hSignInGmtUpdate",new Date(),metaObject);
        log.info(String.valueOf(new Date()));
    }
}
